updated: 2022-01-23_12:32:31-05:00


Schedulers

Workload: set of job descriptions
Scheduler: logic that decides when jobs run
Metric: measurement of scheduling quality

Scheduler 'algebra', given two variables, find the third
f(W,S)=M

Preemptive: When the operating system interrupts a program from running (vs. cooperative)

Workload Assumptions:

  1. Each jobs run for the same amount of time
  2. All jobs arrive at the same time
  3. All jobs only use the CPU (no IO)
  4. The runtime of each job is known

Pasted image 20211018084025

first in first out
shortest job first
shortest to completion first
round robin (preemptive time slices with quantum time slices, cyclic nature of queue)

Example: FIFO

  • Pasted image 20211018084408

  • Turnaround: Completion time - arrival time

  • Pasted image 20211018084436

  • Trace:

  • Pasted image 20211018084455

  • Pasted image 20211018084540

Example: Shortest Job First, with a big first job

What if they didn't run for the same amount of time?
Pasted image 20211018084717

FIFO:
Pasted image 20211018084726

  • when deciding what job to run next, choose the one with smallest run_time
  • Pasted image 20211018084802

Example: Shortest Time to completion first

What if jobs didn't arrive at the same time?
Pasted image 20211018084927

Not good...

  • Policy: switch jobs so we always run the one that will complete the quickest

Pasted image 20211018085007

STCF, great for small jobs who want to run and don't want to wait for a big job, bad for big jobs who could be continually kept on the bottom of the queue so they never run FIFO, great for bigger jobs since everyone is run in order, is not affected by smaller jobs arriving SJF, bad for big jobs if not first since they could never run and bad for small jobs because if a big job ever get's loaded they have to wait for it to be completely finished So yea, worst of both worlds

Example: Round Robin

what if we care about when a job starts?

Response time = first run - arrival time
Pasted image 20211020081120

Other schedulers have poor response time
Pasted image 20211020081506

I/O Aware

what if jobs wanted to use I/O?

Pasted image 20211020081549

Pasted image 20211020081600

MLFQ

what if the runtime of each job is NOT known?

  • Multi-Level Feedback Queue
  • General purpose scheduling

Two job types:

  1. interactive: programs care about response time
  2. batch: programs care about turnaround time

This solution is effectively multiple levels of round-robin

Priorities

Rule 1: If priority(A) > Priority(B), A runs
Rule 2: If priority(A) == Priority(B), A & B run in RR
Rule 3: Processes start at top priority
Rule 4: If job uses whole slice, demote process

Pasted image 20211020081909

Pasted image 20211020082008

Pasted image 20211020082529

Pasted image 20211020082538

problem: unforgiving, gaming the system, hard to tune...

How do we fix processes getting stuck at q0:
every so often we clear the queue, reschedule everything at highest priority

Lottery

Proportional Share

  • Give processes lottery tickets
  • whoever wins runs
  • higher priority = more tickets
int counter = 0;  
int winner = getrandom(0, totaltickets);  
node_t *current = head;  
while(current) {   
	counter += current->tickets;   
	if (counter > winner) break;   
	current = current->next;   
} // current is the winner  

Pasted image 20211020084229

Winner = 102
Pasted image 20211020084323

Pasted image 20211020084332

Pasted image 20211020084344

Pasted image 20211020084359